<template>
  <div class="WorkingSchedule" v-loading="loading">

    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="离职员工姓名" class="myform-item">
          <el-input
            v-model="form.username"
            placeholder="请输入离职员工姓名"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="部门" class="myform-item">
          <el-cascader
            v-model="postIds"
            :options="postlist"
            @change="handleChangeSearch"
            clearable
            :props="Props"
          ></el-cascader>
        </el-form-item>
      </div>

      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
        <el-table-column label="离职员工姓名" align="center" prop="username">
      </el-table-column>
      
      <el-table-column
        label="部门"
        align="center"
        prop="main_dept_name"
      >
      </el-table-column>
      <el-table-column label="离职前状态" align="center" prop="pre_status">
          <template slot-scope="{ row }">
              {{row.pre_status==1?"待入职":row.pre_status==2?"试用期":"正式"}}
          </template>
      </el-table-column>
      <el-table-column label="离职流程状态" align="center" prop="status">
          <template slot-scope="{ row }">
              {{row.status==1?"待离职":row.status==2?"已离职":row.status==3?"未离职":row.status==4?"发起离职审批但还未通过":row.status==5?"失效（离职流程被其他流程强制终止后的状态":""}}
          </template>
      </el-table-column>
      <el-table-column label="离职交接人" align="center" prop="handover_userid">
      </el-table-column>
      <el-table-column label="最后工作日" align="center" prop="last_day">
      </el-table-column>
      <el-table-column label="离职原因" align="center" prop="reason_type">
          <template slot-scope="{ row }">
              {{row.reason_type==1?"家庭原因":row.reason_type==2?"个人原因":row.reason_type==3?"发展原因":row.reason_type==4?"合同到期不续签":row.reason_type==5?"协议解除":row.reason_type==6?"无法胜任工作":row.reason_type==7?"经济性裁员":row.reason_type==8?"严重违法违纪":row.reason_type==9?"其他":""}}
          </template>
      </el-table-column>
      <el-table-column label="离职原因备注" align="center" prop="reason_memo">
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="
        postAdminUserGetdimission
      "
    />
  </div>
</template>

<script>
import {
  postAdminUserGetdimission,
  postAdminRecruitmentInformationGetProfession,
  postAdminRecruitmentInformationaddPosition,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      postIds: "",
      postIdsSearch: "",
      Props: {
        value: "id",
        label: "title",
        children: "position",
        checkStrictly: true,
      },
      postlist: [],
      form: {
        dept_list: "",
        username: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postAdminUserGetdimission(form);
    this.postAdminRecruitmentInformationGetProfession();
  },
  methods: {
    handleChangeSearch(e) {
      console.log("handleChangeSearch------->", e);
      let arr = JSON.parse(JSON.stringify(e));
      this.form.dept_list = arr.pop();
    },
    // 部门
    postAdminRecruitmentInformationGetProfession() {
      postAdminRecruitmentInformationGetProfession().then((res) => {
        this.postlist = res.data;
      });
    },
    // 采购列表
    async postAdminUserGetdimission(data) {
      this.loading = true;
      this.form = data;
      postAdminUserGetdimission(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 添加岗位
    onAddPostPup(formName) {
      let that = this;
      this.$refs[formName].validate((valid, data) => {
        if (valid) {
          console.log("data-------->", data);
          this.loading = true;
          postAdminRecruitmentInformationaddPosition(that.userForm).then(
            (res) => {
              let form = that.form;
              this.postAdminUserGetdimission(form);
              this.dialogVisible = false;
              this.loading = false;
            }
          );
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      console.log("this.form", this.form);
      this.postAdminUserGetdimission(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
